<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>


<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="demoTable">
            搜索订单号：
            <div class="layui-inline">
                <input class="layui-input" name="ordertable_id" id="demoReload1" autocomplete="off">
            </div>
            <button class="layui-btn" data-type="reload">搜索</button>
        </div>


        <table class="layui-hide" id="ordertable" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">订单详情</a>
        </script>

    </div>
</div>

<div id="update-user-layer" style="display: none; padding: 20px">
   <table class="layui-table" id="my_table">
       <thead>
           <th>商品名称</th>
           <th>单价</th>
           <th>数量</th>
       </thead>
       <tbody></tbody>
   </table>
</div>

<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            ordertable = layui.table;

        ordertable.render({
            elem: '#ordertable',
            url: '/order/getAllordertable',
            toolbar: '#toolbarDemo',
            title: '订单信息',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'ordertableId', width: 150, title: '订单号'},
                {field: 'open_id', width: 150, title: '微信用户'},
                {field: 'date', width: 280, title: '生成日期',sort:true},
                {field: 'finish', width: 280, title: '完成日期',sort:true},
                {field: 'total_price', width: 150, title: '总价'},
                {field: 'state', width: 150, title: '状态',templet:function(res){
                        if(res.state==0)return "交易中"
                            if(res.state==1) return "已完成"
                        else return "已取消"
                    }},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            id: 'testReload',

        });

        var $ = layui.$, active = {
            reload: function () {

                var demoReload1 = $('#demoReload1');

                ordertable.reload('testReload', {
                    url: '/order/getByOrdertable_id',
                    where: {
                        ordertable_id: demoReload1.val()
                    }
                }, 'data');

            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        ordertable.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var arry=[];
            arry = obj.data.ordertable_goods
            if (obj.event === 'edit') {
                // 显示弹出层
                layer.open({
                    type: 1,
                    title: '订单详情',
                    skin: 'layui-layer-molv',
                    area: ["500px","300px"],
                    content: $('#update-user-layer')
                });
                $("#my_table tbody").html("");
                var html=new Array();
                for(var i=0;i<arry.length;i++){
                    html.push("<tbody><td>"+arry[i].goods.goodsName+"</td>");
                    html.push("<td>"+arry[i].goods.price+"</td>");
                    html.push("<td>"+arry[i].amount+"</td></tbody>");
                }
                $("#my_table").append(html.join(""));
            }
        });
    });

</script>

</body>
</html>